package com.haha.keymap.v4;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.haha.keymap.v1.SkillConfigData;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Paths;

public class CommonUtil {

    public static SkillConfigData getConfigInfo(String selectedTalent) {
        // 获取当前工作目录
        String currentDir = System.getProperty("user.dir");
        String filePath = Paths.get(currentDir, selectedTalent + "-config.json").toString();
        File file = new File(filePath);
        if (!file.exists()) {
            return null;
        }

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        try (FileReader reader = new FileReader(filePath)) {
            java.lang.reflect.Type configType = new TypeToken<SkillConfigData>() {
            }.getType();
            return gson.fromJson(reader, configType);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static SkillConfigData getAoeConfigInfo(String selectedTalent) {
        // 获取当前工作目录
        String currentDir = System.getProperty("user.dir");
        String filePath = Paths.get(currentDir, selectedTalent + "-aoe-config.json").toString();
        File file = new File(filePath);
        if (!file.exists()) {
            return null;
        }

        Gson gson = new GsonBuilder().setPrettyPrinting().create();

        try (FileReader reader = new FileReader(filePath)) {
            java.lang.reflect.Type configType = new TypeToken<SkillConfigData>() {
            }.getType();
            return gson.fromJson(reader, configType);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
